package com.example.springboot.mapper;


import com.example.springboot.pojo.LeaveRequest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface LeaveRequestMapper {

    @Select("select * from leave_request order by start desc")
    List<LeaveRequest> getList();

    @Insert("insert into leave_request(worker_id,name,department,phone_number,detail,start,end,status)" +
    " values(#{workerId},#{name},#{department},#{phoneNumber},#{detail},#{start},#{end},0)")
    void addRequest(String workerId, String name, String department, String phoneNumber, String detail, String start, String end);

    @Update("update leave_request set status=1 where id=#{id} ")
    void pass(Integer id);

    @Update("update leave_request set status=2 where id=#{id} ")
    void refuse(Integer id);

    @Select("select * from leave_request where worker_id=#{workerId} order by start desc")
    List<LeaveRequest> getByWorkerId(String workerId);
}
